import coffee.Coffeemachine;
import input.Inputs;

import java.lang.Thread;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Scanner;

public class Program {

    public static void main(String[] args) {
        Coffeemachine machine = new Coffeemachine();

        (new Timer()).scheduleAtFixedRate(new TimerTask() {
            long t0 = System.currentTimeMillis();

            @Override
            public void run() {
                if (System.currentTimeMillis() - t0 > 5 * 1000) {
                    t0 += (5 * 1000);
                    machine.request(Inputs.TIMESTEP);
                }
            }
        }, 0, 5 * 1000);

        Scanner scanner = new Scanner(System.in);
        Thread inputsred = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    String input = scanner.nextLine();
                    switch (!input.equals("") ? input.charAt(0) : '\n') {
                        case 'j':
                            machine.request(Inputs.BUTTONON);
                            break;
                        case 'k':
                            machine.request(Inputs.BUTTONOFF);
                            break;
                        case 'm':
                            machine.request(Inputs.BUTTONMILK);
                            break;
                        case 'c':
                            machine.request(Inputs.BUTTONCOFFEE);
                            break;
                    }
                }
            }
        });
        inputsred.start();
    }

}